home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / 140_01.zip / MARGIN.C < prev    next >
Text File  |  1993-06-26  |  2KB  |  111 lines

  1. /* MARGIN.C 22nd Feb 1981
  2.  
  3.     Prompts user to set margins on diablo daisy wheel printer,
  4.     for use with a cut sheet feeder
  5.  
  6.     By    Bill Bolton
  7.         Software Tools
  8.         P.O. Box 80
  9.         Newport Beach
  10.         NSW, 2106
  11.         Australia
  12. */
  13.  
  14. #define MINMARG 0
  15. #define MAXMARG    156
  16. #define MAXTAB 125
  17. #define LSIDE '9'
  18. #define RSIDE '0'
  19. #define HT  0x09
  20. #define ESC 0x1b
  21. #define STDIN 0
  22. #define STDOUT 1
  23. #define LST 2
  24.  
  25. int    odevice;
  26. int    idevice;
  27. int    ldevice;
  28.  
  29. main (argc,argv)
  30.  
  31. int    argc;
  32. char    *argv[];
  33.  
  34. {
  35.     int    lmargin;
  36.     int    rmargin;
  37.     char    lstr[6];
  38.     char    rstr[6];
  39.  
  40.     lmargin = 0;            /* intialisation */
  41.     rmargin = 0;
  42.     odevice = STDOUT;
  43.     idevice = STDIN;
  44.     ldevice = LST;
  45.     sprintf(lstr,"left ");
  46.     sprintf(rstr,"right");
  47.  
  48.     fprintf(odevice,"\n\tCopyright (C) 1981, Software Tools, Sydney,\
  49.  Australia.\n");
  50.     fprintf(odevice,"\tMARGIN Version 1.0 (Diablo)\n\n");
  51.     fprintf(odevice,"\tThis program sets the margins on a Diablo daisy\
  52.  wheel printer, margin\n");
  53.     fprintf(odevice,"\tpositions can only be set in the range 0 to %d\
  54.  from this program.\n\n\t",MAXMARG);
  55.     while (rmargin <= lmargin) {
  56.         fprintf(odevice,"Right margin must be greater than left\
  57.  margin.\n\n");
  58.         lmargin = get_margin(lstr);
  59.         rmargin = get_margin(rstr);
  60.         if (rmargin <= lmargin) {
  61.             fprintf(odevice,"\007\tRight margin error. ");
  62.         }
  63.     }
  64.     fprintf(odevice,"\n\tLeft  margin is set to %d\n",lmargin);
  65.     fprintf(odevice,"\tRight margin is set to %d\n",rmargin);
  66.     set_margin(++lmargin,LSIDE);
  67.     set_margin(++rmargin,RSIDE);
  68.     putc('\r',ldevice);
  69. }
  70.  
  71. /* prompts user for required margin, does range check and return margin */
  72.  
  73. get_margin(str)
  74.  
  75. char    *str;
  76.  
  77. {
  78.     int    margin;
  79.     char    reply[8];
  80.  
  81.     fprintf(odevice,"\tEnter position for %s margin  : ",str);
  82.     fgets(reply,idevice);
  83.     margin = atoi(reply);
  84.     while (margin > MAXMARG || margin < MINMARG) {
  85.         fprintf(odevice,"\007\n\tMargin MUST be in the range 0\
  86.  to %d, renter.\n\n",MAXMARG);
  87.         margin = get_margin(str);
  88.     }
  89.     return(margin);
  90. }
  91.  
  92.  
  93. set_margin(margin,side)
  94.  
  95. int    margin;
  96. int    side;
  97.  
  98. {
  99.     int    i;
  100.  
  101.     if(margin > MAXTAB) {
  102.         fprintf(ldevice,"%c%c%c",ESC,HT,MAXTAB);
  103.         for( i = 1; i <= (margin - MAXTAB); i++)
  104.             putc(' ',ldevice);
  105.     }
  106.     else {
  107.         fprintf(ldevice,"%c%c%c",ESC,HT,margin);
  108.     }
  109.     fprintf(ldevice,"%c%c",ESC,side);
  110. }
  111.